﻿using Abp.Application.Navigation;
using Abp.Threading;
using Abp.UI;
using MyCompanyName.AbpZeroTemplate.Authorization.Users;
using MyCompanyName.AbpZeroTemplate.Organizations;
using MyCompanyName.AbpZeroTemplate.Prm.Document;
using MyCompanyName.AbpZeroTemplate.Sessions;
using MyCompanyName.AbpZeroTemplate.Web.Areas.Mpa.Models.Layout;
using MyCompanyName.AbpZeroTemplate.Web.Areas.Prm.Startup;
using MyCompanyName.AbpZeroTemplate.Web.Controllers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Web;
using System.Web.Mvc;

namespace MyCompanyName.AbpZeroTemplate.Web.Areas.Prm.Controllers
{
    [Abp.Web.Mvc.Authorization.AbpMvcAuthorize/*(MyCompanyName.AbpZeroTemplate.Authorization.AppPermissions.Pages)*/]
    public class HomeController : AbpZeroTemplateControllerBase
    {
        private readonly IUserNavigationManager _userNavigationManager;
        private readonly ISessionAppService _sessionAppService;
        private readonly IOrganizationUnitAppService _organizationService;
        private readonly IDocumentAppService _docService;
        private readonly IUserAppService _userService;

        public HomeController(IUserNavigationManager userNavigationManager,
            IOrganizationUnitAppService organizationService,
            ISessionAppService sessionAppService,
            IDocumentAppService docService,
            IUserAppService userService)
        {
            _userNavigationManager = userNavigationManager;
            _sessionAppService = sessionAppService;
            _organizationService = organizationService;
            _docService = docService;
            _userService = userService;
        }
        public ActionResult ChromeGSETest()
        {
            return View();
        }
        public ActionResult Index()
        {
            var userInfo = AsyncHelper.RunSync(() => _sessionAppService.GetCurrentLoginInformations());

            ViewBag.deptName = _userService.GetUserCompany(userInfo.User.Id);
            ViewBag.userName = userInfo.User.Name;
            ViewBag.userId = userInfo.User.Id;
            return View();
        }

        public ActionResult Download(string fileName)
        {
            string path = System.Web.HttpContext.Current.Request.PhysicalApplicationPath + @"\App_Data\" + fileName;
            return File(path, "application/octet-stream", fileName);
        }

        public async Task<ActionResult> DownloadAuthFile(string path)
        {
            await _docService.GetFile(path);
            return Content("no authority to download");
        }

        /// <summary>
        /// ext的主菜单menu
        /// </summary>
        /// <returns></returns>
        public ActionResult GetMainMenu()
        {
            var sidebarModel = new SidebarViewModel
            {
                Menu = AsyncHelper.RunSync(() => _userNavigationManager.GetMenuAsync(PrmNavigationProvider.MenuName, AbpSession.UserId)),
                CurrentPageName = ""
            };
            return Json(sidebarModel.Menu, JsonRequestBehavior.AllowGet);
        }


        //public ActionResult GetTree()
        //{
        //    List<Prm.Controllers.OrganizationTreeDto> res = new List<OrganizationTreeDto>()
        //    {
        //        new  OrganizationTreeDto(){ id="1", parentId="0", text="111", leaf=false,expanded=true,children=
        //            new List<OrganizationTreeDto>()
        //            {
        //                new  OrganizationTreeDto(){ id="2", parentId="1", text="222", leaf=true,children=null} 
        //            }}
        //    };
        //    return Json(res, JsonRequestBehavior.AllowGet);
        //}


        public ActionResult GetCmoProgressData() { 
            var lst=new List<MyCompanyName.AbpZeroTemplate.Prm.Project.CMOProgress>();
            lst.Add(new MyCompanyName.AbpZeroTemplate.Prm.Project.CMOProgress("原料", "S.M1" ));
            lst.Add(new MyCompanyName.AbpZeroTemplate.Prm.Project.CMOProgress("原料", "S.M2" ));
            lst.Add(new MyCompanyName.AbpZeroTemplate.Prm.Project.CMOProgress("原料", "S.M3" ));
            lst.Add(new MyCompanyName.AbpZeroTemplate.Prm.Project.CMOProgress("原料", "S.M4" ));
            lst.Add(new MyCompanyName.AbpZeroTemplate.Prm.Project.CMOProgress("原料", "S.M5" ));

             lst.Add(new MyCompanyName.AbpZeroTemplate.Prm.Project.CMOProgress("中间体(打通工艺）", "xxxx05" ));
            lst.Add(new MyCompanyName.AbpZeroTemplate.Prm.Project.CMOProgress("中间体(打通工艺）", "xxxx10" ));
            lst.Add(new MyCompanyName.AbpZeroTemplate.Prm.Project.CMOProgress("中间体(打通工艺）", "xxxx20" ));
          

             lst.Add(new MyCompanyName.AbpZeroTemplate.Prm.Project.CMOProgress("工艺路线包含中控（优化工艺）", "Step1" ));
            lst.Add(new MyCompanyName.AbpZeroTemplate.Prm.Project.CMOProgress("工艺路线包含中控（优化工艺）", "Step2" ));
            lst.Add(new MyCompanyName.AbpZeroTemplate.Prm.Project.CMOProgress("工艺路线包含中控（优化工艺）", "Step3" ));
            lst.Add(new MyCompanyName.AbpZeroTemplate.Prm.Project.CMOProgress("工艺路线包含中控（优化工艺）", "Step4" ));
            lst.Add(new MyCompanyName.AbpZeroTemplate.Prm.Project.CMOProgress("工艺路线包含中控（优化工艺）", "Step5" ));

            return Json( lst , JsonRequestBehavior.AllowGet);
        }
    }
}